package autotest

import (
	autotest_mock "app/app_src/framework/autotest/mock"
	autotest_util "app/app_src/framework/autotest/util"

	"github.com/gin-gonic/gin"

	"net/http"

	"net/http/httptest"
)

type TestFunc func(router *gin.Engine)

// 运行 web 测试用例
func RunWebTest(testFunc TestFunc) {
	// 获取应用目录
	appDir := autotest_util.CalcAppDir()
	// 模拟 Gin
	router := autotest_mock.MockGin(appDir)

	// 调用测试函数
	testFunc(router)
}

// 发送请求
func SendRequest(router *gin.Engine, req *http.Request) *httptest.ResponseRecorder {
	// 调用请求
	w := httptest.NewRecorder()
	router.ServeHTTP(w, req)

	return w
}
